package com.ys.web.pay.service.impl;

import com.ys.base.EnumType;
import com.ys.utils.base.j2se.DateHandler;
import com.ys.utils.base.j2se.StringHandler;
import com.ys.web.pay.mapper.StatisticalMapper;
import com.ys.web.pay.model.po.UserFlow;
import com.ys.web.pay.service.StatisticalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @author quxinjun
 * @version 1.0.0
 * @ClassName StatisticalServiceImpl.java
 * @Description TODO
 * @createTime 2022年02月16日 11:51:00
 */
@Service
public class StatisticalServiceImpl implements StatisticalService {

    @Autowired
    private StatisticalMapper statisticalMapper;

    @Override
    public List<Map<String, Object>> getAllStatisticalType() {
        return EnumType.AccountFlowType.getAll();
    }

    @Override
    public Map<String, Object> getFlowByUserId(Long uid, String type,int payChannel, int pageNumber,
                                               int pageSize, String queryDate,String dayTime) {
        Map<String, Object> result = new HashMap<>();
        if (StringHandler.isEmpty(queryDate)) {
            queryDate = DateHandler.getDate(new Date(), "yyyy-MM");
        }
        List<String> strings = Arrays.asList(EnumType.AccountFlowType.getValue(type).split(","));
        //查询的是红包  添加收入和支出字段
        if ("1".equals(type) || "4".equals(type)) {
            Map<String, Object> add = statisticalMapper.getRedPacketNav(uid,payChannel, strings, queryDate, 1,dayTime);
            Map<String, Object> sub = statisticalMapper.getRedPacketNav(uid,payChannel, strings, queryDate, 2,dayTime);
//            result.put("navList", navList);
            result.put("add", add.get("val"));
            result.put("sub", sub.get("val"));
        }
        int limit = (pageNumber - 1) * pageSize;
        List<UserFlow> userFlowList = statisticalMapper.getFlowByUserId(uid,payChannel, strings, limit, pageSize, queryDate,dayTime);
        result.put("userFlowList", userFlowList);
        return result;
    }

}
